#include "xxdd.h"
#include "key_task.h"

#include "key.h"
#include "led.h"

//-----任务类及任务变量在这里定义----------------

Class(Key0Task)
{
  C_task task;             // 每个任务类都必须有task变量
  unsigned char keystatus; //
  unsigned char keynum;    //
}
key0;

//------------------任务函数在这里实现------------------------------------------

TaskFun(Key0Task)
{

  {
    typedef enum
    {
      IDLE_STATE,             // 空闲
      PRESS_DETECTED_STATE,   // 按键按下
      RELEASE_DETECTED_STATE, // 按键释放
      SHORT_PRESS_STATE,      // 短按
      LONG_PRESS_STATE,       // 长按
      DOUBLE_PRESS_STATE,     // 双击
      LONG_PRESS_STATE_END    // 长按结束状态
    } ButtonState;

    
    u8 key = 0;

    while (1)
    {
      key = KEY_Scan(0); //
      switch (key)
      {
      case KEY0_PRES:
        LED0 = !LED0;
        break;
      case KEY1_PRES:
        LED1 = !LED1;
        break;
      case WKUP_PRES:
        LED0 = !LED0;
        LED1 = !LED1;
        break;
      default:
        WaitX(10);
      }
    }
  }
}
EndFun

//------------------------------------------------------------------------

void UpdateKeyTimers()
{
	UpdateTimer(key0);
}
void runkeytask()
{
	RunTask(Key0Task, key0);
}